import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:m6/business/home/page/home.dart';
import 'package:m6/business/Me/me.dart';
import 'package:flutter/material.dart';

class Tabbar extends StatefulWidget {
  const Tabbar({super.key});

  @override
  State<Tabbar> createState() => _TabbarState();
}

class _TabbarState extends State<Tabbar> {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<TabbarController>(
      init: TabbarController(),
      builder: (controller) => Scaffold(
        // appBar: AppBar(
        //   backgroundColor: Colors.blue,
        //   title: Text(controller.barItems[controller.currentIndex].label ?? ''),
        // ),
        body: PageView.builder(
          itemBuilder: (context, index) {
            return controller.pages[index];
          },
          physics: const NeverScrollableScrollPhysics(),
          controller: controller.pageCon,
          onPageChanged: (int index) {
            controller.currentIndex = index;
            controller.update();
          },
        ),
        bottomNavigationBar: BottomNavigationBar(
          items: controller.barItems,
          currentIndex: controller.currentIndex,
          selectedItemColor: Colors.cyan,
          unselectedItemColor: Colors.grey,
          selectedFontSize: 12,
          unselectedFontSize: 12,
          onTap: (int index) {
            controller.pageCon.jumpToPage(index);
          },
        ),
      ),
    );
  }
}

class TabbarController extends GetxController {
  int currentIndex = 0;
  List<Widget> pages = [const Home(), const Me()];

  PageController pageCon = PageController();

  List<BottomNavigationBarItem> barItems = [
    const BottomNavigationBarItem(
        label: 'Home',
        icon: Icon(Icons.star),
        activeIcon: Icon(Icons.star_border_rounded)),
    const BottomNavigationBarItem(
        label: 'Me',
        icon: Icon(Icons.accessibility),
        activeIcon: Icon(Icons.accessibility_new)),
  ];

  @override
  void onInit() {
    // TODO: implement onInit
    currentIndex = 0;
    super.onInit();
  }
}

/*
class _TabbarState extends State<Tabbar> {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(
        backgroundColor: Colors.blue,
        middle: Text(
          "Tabbar",
          style: TextStyle(color: Colors.white, fontSize: 24),
        ),
      ),
      child: Container(
        margin: const EdgeInsets.only(top: 0),
        color: Colors.white,
      ),
    );
  }
}
*/
